<?php
$cs = Yii::app()->getClientScript();
$cs->registerCSSFile(Yii::app()->request->baseUrl . '/css/mobile/booking_find.css');
$cart = new BWCart();
$view = $cart->getView(array('itemData' => array('paymentStatus' => bcart::Payment_Status_Not_Paid)));
$view2 = $cart->getView(array('itemData' => array('paymentStatus' => bcart::Payment_Status_Waiting_Paid)));
foreach ($view2 as $cartList) {
    //reset status
    $cartList->addItem('paymentStatus', bcart::Payment_Status_Not_Paid);
}
$view = $view + $view2;
$totalCount = count($view);
?>
<div data-role='page' id='demo-page'>
    <div data-role="header">
        <h1>支付</h1>
    </div>
    <div data-role='content' id='mainContent' style="padding: 5px;">
<?php
$screen = Blyn::app()->getUIManager()->getCurrentScreen();
$wxControl = $screen->getChildControl('BUIWXControl_1');
$wxControl->renderView('booking_home', array());

?>
<script type="text/javascript">
    $(document).ready(function() {
        $("#selectAll").click(function() {
            if ($(this).attr("checked") == "checked") {
                $(":checkbox").attr("checked", true);
            } else {
                $(":checkbox").attr("checked", false);
            }
        });

    });
</script> 
<script type="text/javascript">
    $(function() {
        $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
        $('.tree li.parent_li > span').on('click', function(e) {
            var children = $(this).parent('li.parent_li').find(' > ul > li');
            if (children.is(":visible")) {
                children.hide('fast');
                $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
            } else {
                children.show('fast');
                $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
            }
            e.stopPropagation();
        });
    });</script>
<script type="text/javascript">
    $(function() {
        $("#Event_Shop_CX").click(function() {
            document.getElementById("Event_Shop_CX_View").style.display = '';
            document.getElementById("Event_Clothes_CX_View").style.display = 'none';
        });
        $("#Event_Clothes_CX").click(function() {
            document.getElementById("Event_Shop_CX_View").style.display = 'none';
            document.getElementById("Event_Clothes_CX_View").style.display = '';
        });
    });</script>
<?php
$form = $this->beginWidget('CActiveForm', array(
    "id" => "findBookableForm",
    'enableAjaxValidation' => FALSE,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
        ));
$model = new BDynamicFormModel();
?>
    <span><?php echo '我的未支付订单'; ?></span>
<div class="modal-header" style="background-color:#eeeeee;">
    <h5><?php echo $wxControl->getLink(array('name' => '我的订单记录', 'id' => 'showMyBookingList_1'), array('paymentStatus' => 'paid')); ?></h5>
</div>
<table data-role="table" id="table-custom-2" data-mode="columntoggle" class="ui-body-d ui-shadow table-stripe ui-responsive" data-column-btn-theme="b" data-column-btn-text="显示列" data-column-popup-theme="a">
    <thead>
        <tr>
            <th data-priority="3">
                <input type="checkbox"  id="selectAll" data-role="none" style="display:inline !important;"/> 
            </th>   
            <th data-priority="3"><?php echo '序号'; ?></th>
            <th data-priority="3"><?php echo '支付ID'; ?></th>
            <th data-priority="1"><?php echo '名称'; ?></th>
            <th data-priority="3"><?php echo '产品ID'; ?></th>
            <th data-priority="1"><?php echo '单价'; ?></th>
            <th data-priority="1"><?php echo '数量'; ?></th>
            <th data-priority="1"><?php echo '合计'; ?></th>
            <th data-priority="1"><?php echo '操作'; ?></th>
        </tr> 
    </thead>
    <fieldset>
        <tbody>
            <?php
            $totalMoney = 0;
            $serial = 0;
            foreach ($view as $cartList) {
                if ($cartList instanceof BTreeList) {
                    $serial++;
                    $cartId = $cartList->getId();
                    $price = $cartList->getItem('price')->value;
                    $unit = $cartList->getItem('moneyUnit')->value;
                    $quantity = $cartList->getItem('quantity')->value;
                    $productName = $cartList->getItem('productName')->value;
                    $productId = $cartList->getItem('productId')->value;
                    $total = $price * $quantity;
                    if ($total != NULL)
                        $totalMoney += $total;
                }
                ?>
                <tr>

                    <td><label class="checkbox">
                            <input type="checkbox" name="checkbox[]" value="<?php echo $cartId; ?>" data-role="none" style="display:inline !important;"/> 
                        </label></td>
                    <td> <?php echo $serial; ?> </td>
                    <td> <?php echo $cartId; ?> </td>
                    <td> <?php echo $productName; ?> </td>       
                    <td> <?php echo $productId; ?> </td>      
                    <td> <?php echo $price; ?> </td>   
                    <td> <?php echo $quantity; ?> </td>   
                    <td> <?php echo $total; ?> </td>   
                    <td>
                        <div class="row-fluid">                         
                            <?php
                            echo $wxControl->getLink(array('name' => '修改', 'id' => 'showAddBookable_1'), array(
                                'htmlOptions' => array(
                                    'enctype' => 'multipart/form-data')
                            ));
                            ?>
                            <br/>
                            <?php
                            echo $wxControl->getLink(array('name' => '删除', 'id' => 'deleteBookable_1'), array(
                                 'cartId'=>$cartId,
                                'htmlOptions' => array(
                                    'enctype' => 'multipart/form-data')
                            ));
                            ?> 
                        </div>                      
                    </td>
                </tr>
            <?php } ?>
            <tr>
                <td></td><td></td><td></td><td></td><td></td><td></td>
                <td><strong>总金额：</strong></td><td><?PHP echo $totalMoney; ?></td><td></td>
            </tr>
        </tbody>
    </fieldset>
</table>

<div class="row-fluid">
    <?php
    $paidMoney = $totalMoney;
    $paidCount = $totalCount;
    ?>
    <?php $paidUrl = $wxControl->getLinkUrl(array('name' => 'pay','id' => 'payNow_1'), array('paidMoney' => $paidMoney,'paidCount' => $paidCount));?>
    <script type="text/javascript">
    $(document).ready(function() {
        $("#pay_now").click(function() {
            var paidCount = $("#paid_count").html();
            var paidMoney = $("#paid_money").html();
            /*执行微信端支付接口*/
            //location.href = "<?php echo $paidUrl;?>";
	     location.href="http://www.hualvhb.cn/pay/weixin/jsapicall.php?pUrl=http://stage.billyn.net<?php echo $paidUrl;?>&pM=<?php echo $paidMoney; ?>&pC=<?php echo $paidCount; ?>";
        });
    });
    </script>
    <div data-role="popup" id="purchase" data-theme="a" data-overlay-theme="b" class="ui-content" style="max-width:340px; padding-bottom:2em;">
        <h3>预订支付</h3>
        <p><strong>预订项数量：</strong><span class="text-warning" id="paid_count"><?php echo $paidCount; ?></span></p>
        <p><strong>支付总金额：</strong><span class="text-primary" id="paid_money"><?php echo $paidMoney; ?></span></p>

        <a href="#" id="pay_now" class="ui-btn ui-corner-all ui-btn-b ui-icon-check ui-btn-icon-left ui-btn-inline ui-mini">确认支付</a>
        <a href="#" data-rel="back" class="ui-btn ui-corner-all ui-btn-inline ui-mini">取消</a>
    </div>
    <fieldset class="ui-grid-a">
        <div class="ui-block-a"><a href="#purchase" class="ui-btn ui-corner-all ui-mini ui-btn-active" data-rel="popup" data-position-to="window" data-transition="pop">确认支付</a></div>
        <div class="ui-block-b">
        <?php
        if(isset($cartId)){
        echo $wxControl->getLink(array('name' => '删除', 'id' => 'deleteBookable_1'), array(
            'cartId'=>$cartId,
            'htmlOptions' => array(
                'class'=>'ui-btn ui-mini ui-btn-corner-all',
                'enctype' => 'multipart/form-data')));
        }
        else 
        {
            echo $wxControl->getLink(array('name' => '删除', ), array(
            'htmlOptions' => array(
                'class'=>'ui-btn ui-mini ui-btn-corner-all',
                'enctype' => 'multipart/form-data')));
        }
        ?>
        </div>
    </fieldset>
</div>   
<div id="myModal2" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
<div><input type="hidden" name="curPageNo" value="1"></div>

<?php $this->endWidget(); ?>
</div>
<div data-role="footer" data-position="fixed">
    <div data-role="navbar">
        <ul>
            <li><a href="#" id="find" data-icon="search">分类查询</a></li>
            <li><a href="#" id="mybooking" data-icon="shop" class="ui-btn-active">我的预订</a></li>
            <li><a href="#" data-icon="gear">其他</a></li>
        </ul>
    </div><!-- /navbar -->
</div><!-- /footer -->